package com.skycode.servlet;

import com.skycode.dao.NewsDao;
import com.skycode.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/noticeDel.jsp")
public class NoticeDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String noticeId = req.getParameter("NoticeId");
        int result =  (new NoticeDao()).delete( Integer.parseInt(noticeId) );
        if (result > 0) {
            //补充知识 跳转到网页news.html中
            resp.sendRedirect("notice.html");//使用结果对象 完成页面网址跳转
        }else {//失败显示错误提示页面
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
